package com.atguigu.principle.inversion.improve;

/**
 * @author gcq
 * @Create 2020-09-28
 */
public class DependecyInversion {
    public static void main(String[] args) {
        // 客户端无需改变
        Person person = new Person();
        person.receive(new Email());
        person.receive(new WeiXin());
    }
}

interface IReceiver {
    public String getInfo();
}
class Email implements IReceiver {
    @Override
    public String getInfo() {
        return "电子邮件消息：hello world";
    }
}
// 增加微信
class WeiXin implements IReceiver {

    @Override
    public String getInfo() {
        return "微信消息: hello ok";
    }
}

class Person {
    public void receive(IReceiver receiver) {
        System.out.println(receiver.getInfo());
    }
}
